package com.atguigu.lease.web.app.service.impl;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;

import com.atguigu.lease.common.sms.AliyunSMSConfiguration;
import com.atguigu.lease.web.app.service.SmsService;

import org.springframework.stereotype.Service;

@Service
public class SmsServiceImpl implements SmsService {


//    @Autowired
//    private Client client;

    /**
     * @param phone
     * @param code
     * @Desceription: 发送短信验证码
     * @Return: void
     * @Author: yangchengbao
     * @Date: 2025-01-04 14:01:98
     */
    @Override
    public void sendCode(String phone, String code) {
        AliyunSMSConfiguration aliyunSMSConfiguration = new AliyunSMSConfiguration();
        Client client = aliyunSMSConfiguration.smsClient();
        SendSmsRequest smsRequest = new SendSmsRequest();
        smsRequest.setPhoneNumbers(phone);
        smsRequest.setSignName("阿里云短信测试");
        smsRequest.setTemplateCode("SMS_154950909");
        smsRequest.setTemplateParam("{\"code\":\"" + code + "\"}");

        try {
            client.sendSms(smsRequest);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
